package auctionhaus



import grails.test.mixin.*
import org.junit.*

/**
 * See the API for {@link grails.test.mixin.services.ServiceUnitTestMixin} for usage instructions
 */
@TestFor(BidService)
@Mock([Bid, Customer, Listing, CustomerService, ListingService])
class BidServiceTests {
    def bidService
    def customerService
    def listingService
    Customer bidder
    Listing listing

    public void setUp() {
        bidService = new BidService()
        customerService = new CustomerService()
        listingService = new ListingService()

        bidder = customerService.addCustomer("johndoe@acme.com", "asdfwe")
        listing = listingService.addListing("new listing", "description", new Date()+1, bidder, 3)
    }

    void testAddBid() {
        def bidInstance = bidService.addBid(listing, bidder, 5)
        assert bidInstance.id > 0
    }

    void testInvalidBid() {
        def bidInstance = bidService.addBid(listing, bidder, 2)
        assertNull bidInstance.id
        assert bidInstance.listing.hasErrors()
    }

    public void tearDown() {
        bidService = null
        customerService = null
        listingService = null
        bidder = null
        listing = null
    }
}
